using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestSelectMgr : MonoBehaviour
{
    List<MeshRenderer> ms;
    public Transform boxStart, boxEnd, ringFar, ringNear, circle;
    public float angle;
    public SelectMgr selectMgr;
    private void Start()
    {
        Test();
    }
    public void OnGUI()
    {
        Rect buttonRect = new Rect(10, 10, 100, 30);

        float ys = 40;
        float i = 0;

        if (GUI.Button(buttonRect, "GetSelectByCircle"))
        {
            for (global::System.Int32 j = 0; j < ms.Count; j++)
            {
                ms[j].material.color = Color.white;
            }
            List<SelectObje> sd =  selectMgr.GetSelectByCircle<SelectObje>(circle.transform.position, circle.transform.localScale.x * 0.5f, 1 << 31);
            if (sd != null)
            {
                for (global::System.Int32 j = 0; j < sd.Count; j++)
                {
                    sd[j].Renderer.material.color = Color.red;
                }
            }
        }

        i = 1;
        buttonRect = new Rect(10, 10 + i * ys, 100, 30);
        if (GUI.Button(buttonRect, "GetSelectByRing"))
        {
            for (global::System.Int32 j = 0; j < ms.Count; j++)
            {
                ms[j].material.color = Color.white;
            }
            List<SelectObje> sd = selectMgr.GetSelectByRing<SelectObje>(ringFar.transform.position, ringFar.transform.localScale.x * 0.5f, ringFar.transform.localScale.x * ringNear.transform.localScale.x * 0.5f, 1 << 31);
            if (sd != null)
            {
                for (global::System.Int32 j = 0; j < sd.Count; j++)
                {
                    sd[j].Renderer.material.color = Color.red;
                }
            }
        }

        i = 2;
        buttonRect = new Rect(10, 10 + i * ys, 100, 30);
        if (GUI.Button(buttonRect, "GetSelectbyBox"))
        {
            for (global::System.Int32 j = 0; j < ms.Count; j++)
            {
                ms[j].material.color = Color.white;
            }
            List<SelectObje> sd = selectMgr.GetSelectbyBox<SelectObje>(boxStart.transform.position, boxEnd.transform.position, 1, 1 << 31);
            if (sd != null)
            {
                for (global::System.Int32 j = 0; j < sd.Count; j++)
                {
                    sd[j].Renderer.material.color = Color.red;
                }
            }
        }

        i = 3;
        buttonRect = new Rect(10, 10 + i * ys, 100, 30);
        if (GUI.Button(buttonRect, "GetSelectBySector"))
        {
            for (global::System.Int32 j = 0; j < ms.Count; j++)
            {
                ms[j].material.color = Color.white;
            }
            List<SelectObje> sd = selectMgr.GetSelectByFan<SelectObje>(circle.transform.position, circle.transform.localScale.x * 0.5f, circle.transform.forward, angle, 1 << 31);
            if (sd != null)
            {
                for (global::System.Int32 j = 0; j < sd.Count; j++)
                {
                    sd[j].Renderer.material.color = Color.red;
                }
            }
            FanShape.Instance.GenerateFan(30, .5f, angle * 2);
        }

        i = 4;
        buttonRect = new Rect(10, 10 + i * ys, 100, 30);
        if (GUI.Button(buttonRect, "GetSelectbyEllipse"))
        {
            for (global::System.Int32 j = 0; j < ms.Count; j++)
            {
                ms[j].material.color = Color.white;
            }
            List<SelectObje> sd = selectMgr.GetSelectbyEllipse<SelectObje>(circle.transform.position, circle.transform.rotation, circle.transform.localScale * .5f, 1 << 31);
            if (sd != null)
            {
                for (global::System.Int32 j = 0; j < sd.Count; j++)
                {
                    sd[j].Renderer.material.color = Color.red;
                }
            }
            FanShape.Instance.GenerateFan(30, .5f, angle * 2);
        }
    }
    public void Test()
    {
        Vector3 pos = Vector3.zero;
        ms = new List<MeshRenderer>();

        for (int i = 0; i < 30; i++)
        {
            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
            ms.Add(go.GetComponent<MeshRenderer>());
            go.AddComponent<SelectObje>();
            pos = Random.insideUnitSphere * 20;
            pos.y = 0;
            go.transform.position = pos;
        }
    }
}
